package com.ruoyi.project.web.WebUser.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.web.WebUser.domain.WebUser;
import com.ruoyi.project.web.WebUser.service.IWebUserService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户Controller
 * 
 * @author ruoyi
 * @date 2021-02-19
 */
@Controller
@RequestMapping("/web/WebUser")
public class WebUserController extends BaseController
{
    private String prefix = "web/WebUser";

    @Autowired
    private IWebUserService webUserService;

    @RequiresPermissions("web:WebUser:view")
    @GetMapping()
    public String WebUser()
    {
        return prefix + "/WebUser";
    }

    /**
     * 查询用户列表
     */
    @RequiresPermissions("web:WebUser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WebUser webUser)
    {
        startPage();
        List<WebUser> list = webUserService.selectWebUserList(webUser);
        return getDataTable(list);
    }

    /**
     * 导出用户列表
     */
    @RequiresPermissions("web:WebUser:export")
    @Log(title = "用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WebUser webUser)
    {
        List<WebUser> list = webUserService.selectWebUserList(webUser);
        ExcelUtil<WebUser> util = new ExcelUtil<WebUser>(WebUser.class);
        return util.exportExcel(list, "WebUser");
    }

    /**
     * 新增用户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户
     */
    @RequiresPermissions("web:WebUser:add")
    @Log(title = "用户", businessType = BusinessType.INSERT)
    @PostMapping("/addSave")
    @ResponseBody
    public AjaxResult addSave(WebUser webUser)
    {
        System.out.println(webUser);
        return toAjax(webUserService.insertWebUser(webUser));
    }

    /**
     * 修改用户
     */
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
    {
        WebUser webUser = webUserService.selectWebUserById(userId);
        mmap.put("webUser", webUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户
     */
    @RequiresPermissions("web:WebUser:edit")
    @Log(title = "用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WebUser webUser)
    {
        return toAjax(webUserService.updateWebUser(webUser));
    }

    /**
     * 删除用户
     */
    @RequiresPermissions("web:WebUser:remove")
    @Log(title = "用户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(webUserService.deleteWebUserByIds(ids));
    }

    @GetMapping("/login")
    public String edit()
    {
        return prefix + "/edit";
    }

    @PostMapping( "/checkNameUnique")
    @ResponseBody
    public int checkNameUnique(WebUser webUser)
    {
        return webUserService.checkNameUnique(webUser);
    }
    @PostMapping( "/login")
    @ResponseBody
    public Boolean login(WebUser webUser)
    {

        return webUserService.login(webUser);
    }
}
